<template>
  <el-drawer v-model="drawerVisible" :destroy-on-close="true" size="450px" :title="`${drawerProps.row.datasetName}数据集`">
    <el-form
      ref="ruleFormRef"
      label-width="100px"
      label-suffix=" :"
      :disabled="drawerProps.isView"
      :model="drawerProps.row"
      :hide-required-asterisk="drawerProps.isView"
    >
      <el-form-item label="数据集名称" prop="datasetName">
        <el-input v-model="drawerProps.row!.datasetName" placeholder="请填写数据集名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="样本数" prop="numSamples">
        <el-input v-model="drawerProps.row!.numSamples" placeholder="请填写数据集样本数" clearable></el-input>
      </el-form-item>
      <el-form-item label="根路径" prop="rootPath">
        <el-input v-model="drawerProps.row!.rootPath" placeholder="请填写数据集根路径" clearable></el-input>
      </el-form-item>
      <el-form-item label="形状" prop="shape">
        <el-input v-model="drawerProps.row!.shape" placeholder="请填写数据集形状" clearable></el-input>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-input v-model="drawerProps.row!.type" placeholder="请填写数据集类型" clearable></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="drawerVisible = false">取消</el-button>
      <el-button v-show="!drawerProps.isView" type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts" name="DatasetDrawer">
import { ref, reactive } from "vue";
import { entrain } from "@/utils/dict";
import { ElMessage, FormInstance } from "element-plus";
import {Dataset, Model} from "@/api/interface";
import UploadImg from "@/components/Upload/Img.vue";
import UploadImgs from "@/components/Upload/Imgs.vue";
import { getDModelList } from "@/api/modules/new2";



interface DrawerProps {
  title: string;
  isView: boolean;
  row: Partial<Dataset.ResDatasetList>;
  api?: (params: any) => Promise<any>;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  isView: false,
  title: "",
  row: {}
});

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params;
  drawerVisible.value = true;
};

// 提交数据（新增/编辑）
const ruleFormRef = ref<FormInstance>();
const  handleSubmit = () => {
    try {
      drawerProps.value.api!(drawerProps.value.row);
      ElMessage.success({ message: `${drawerProps.value.title}数据集成功！` });
      drawerProps.value.getTableList!();
      drawerVisible.value = false;
    } catch (error) {
      console.log(error);
    }


};

defineExpose({
  acceptParams
});
</script>
